package org.rapan;

import org.rapan.jpa.Consultant;

import com.vaadin.ui.TabSheet;

@SuppressWarnings("serial")
public class ContentSheet extends TabSheet {
	private Consultant c;

	public ContentSheet(Consultant c) {
		this.c = c;
		if (c.getPosition() == Position.Admin) {
			initAdminSheets();
		} else {
			initConsultantSheets();
		}

	}

	private void initAdminSheets() {
		final ConsultantForm cf = new ConsultantForm() {

			@Override
			public void successfulEdit() {

			}
		};
		addTab(cf, "Create Consultant");
		final SearchConsultantLayout scl = new SearchConsultantLayout();
		addTab(scl, "Search Consultant");
		final CompanyForm comF = new CompanyForm();
		addTab(comF, "Add Company");
		addListener(new SelectedTabChangeListener() {

			public void selectedTabChange(SelectedTabChangeEvent event) {
				comF.clearForm();
				cf.clearForm();
				scl.reset();
			}
		});

	}

	private void initConsultantSheets() {
		final ReportForm rf = new ReportForm(c);
		ProfileLayout profile = new ProfileLayout(c, false) {

			@Override
			public void editButtonSelected(Consultant c) {
			}
		};
		addTab(profile, "Profile");
		addTab(rf, "Create Report");
		addListener(new SelectedTabChangeListener() {

			public void selectedTabChange(SelectedTabChangeEvent event) {
				rf.clearForm();

			}
		});

	}
}
